package it.unito.di.javarole;


public class RelationsSet<T extends RoleInterface> extends java.util.Vector<T> {
	
	int maxSize;
	
	public Object[] invoke(String methodName, Object... pars) throws Exception{
		Class[] classes = new Class[pars.length];
		int i=0;
		for(Object o : pars){
			classes[i++]=o.getClass();
		}
		Class c = super.get(0).getClass();
		java.lang.reflect.Method m = c.getMethod(methodName, classes);
		Object[] sought= new Object[size()];
		for(i =0;i<size();i++){
			sought[i] = m.invoke(get(i), pars);
		}
		return sought;
	}
	
	public Object[] invokeThat(String methodName, Object... pars) throws Exception{
		Class[] classes = new Class[pars.length];
		int i=0;
		for(Object o : pars){
			classes[i++]=o.getClass();
		}
		Class c = get(0).getThat().getClass();
		java.lang.reflect.Method m = c.getMethod(methodName, classes);
		Object[] sought= new Object[size()];
		for(i =0;i<size();i++){
		sought[i] = m.invoke(get(i).getThat(), pars);
		}
		return sought;
	}
	
	
	public RelationsSet(T from){
		super();
		add(from);
		maxSize=1;
		
	}
	public RelationsSet(T[] froms){
		super();
		for(T from : froms){
			add(from);
		}
		maxSize=froms.length;
	}
	
	
}


